home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / libeatmydata / eatmydata.sh
Encoding:
Text File  |  2011-01-04  |  1.9 KB  |  68 lines

  1. # Copyright ┬⌐: 2010, Modestas Vainius <modax@debian.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16. libeatmydata="/usr/lib/libeatmydata/libeatmydata.so"
  17. name="eatmydata"
  18.  
  19. eatmydata_error()
  20. {
  21.     echo "$name error: $1" >&2
  22.     exit 1
  23. }
  24.  
  25. eatmydata_exec()
  26. {
  27.     local cmd
  28.     cmd="$1"
  29.     if [ "${cmd#*/*}" = "${cmd}" ]; then
  30.         # $cmd does not contain '/'. Look in $PATH avoiding loops with self.
  31.         local self save_ifs path exe ok
  32.  
  33.         self="`readlink -f "$0"`"
  34.         save_ifs="$IFS"
  35.         IFS=":"
  36.         ok=""
  37.         for path in $PATH; do
  38.             exe="${path}/$cmd"
  39.             # Avoid loops with self
  40.             if [ -x "$exe" ] && [ "`readlink -f "$exe"`" != "$self" ]; then
  41.                 ok="yes"
  42.                 break
  43.             fi
  44.         done
  45.         IFS="$save_ifs"
  46.         if [ -n "$ok" ]; then
  47.             cmd="$exe"
  48.         else
  49.             eatmydata_error "unable to find '$cmd' in PATH"
  50.         fi
  51.     fi
  52.  
  53.     # Preload libeatmydata
  54.     if [ -n "$LD_PRELOAD" ]; then
  55.         export LD_PRELOAD="$libeatmydata $LD_PRELOAD"
  56.     else
  57.         export LD_PRELOAD="$libeatmydata"
  58.     fi
  59.     # Execute requested command
  60.     shift
  61.     exec "$cmd" "$@"
  62. }
  63.  
  64. # Verify environment
  65. if [ ! -f "$libeatmydata" ]; then
  66.     eatmydata_error "could not find $name library $libeatmydata"
  67. fi
  68.